This section takes a look at some of the commonly used drawing APIs in cocos2d-x;
Let's take a look at a tool class to quickly specify the location of the game window, such as top left and top right;VisibleRect. h
#ifndef __VISIBLERECT_H__#define __VISIBLERECT_H__#include "cocos2d.h"class VisibleRect{public: static cocos2d::Rect getVisibleRect(); static cocos2d::Vec2 left(); static cocos2d::Vec2 ri
http://blog.csdn.net/neng18/article/details/38083987
The "emboss" image effect refers to the foreground projecting background of the image. Common in some monument carving, to achieve relief is actually very simple. We calculate the pixel of the image and the pixel at the top left, and add a grayscale. This grayscale represents the background color. Here we set this interpolation value to 128 (the image RGB value is 0-255). At the same time, we should also convert the difference between the two
(glProgramState);}
The content of WaterEffectSprite is actually very simple. It only inherits the Sprite type and then changes its fragment shader to use WaterEffect. fsh, while WaterEffect. fsh is the place where we need to truly implement the effect logic ~
OK. After the preparation is complete, we can repeat our sleeves and start to get started :)
# "Rotate" pixels
The first method is similar to "Rotating" pixels. You can refer to the explanations here. In addition, there is also an HLSL
This class mainly provides coordinates at various special positions on the screen. The header file code is attached:
1 class visiblerect 2 {3 Public: 4 static cocos2d: rect getvisiblerect (); // obtain the screen rectangle 5 6 static cocos2d: vec2 left (); // left middle, 7 static cocos2d: vec2 right (); // 8 Static cocos2d: vec2 top (); // 9 static cocos2d:
; max_index)Max_index = vertices-> at (ano). index;If (vertices-> at (ano). x> max_x){Max_x = vertices-> at (ano). x;Right = vertices-> at (ano );}If (vertices-> at (ano). x {Min_x = vertices-> at (ano). x;Left = vertices-> at (ano );}}}// Determine whether the center of gravity is within the rangePoint vec1, vec2;Vec1.x = mass. x-left. x; vec1.y = mass. y-left. y;Vec2.x = right. x-left. x;
triangles are drawn, and the rendering logic of the real dials is fully implemented when the GPU shading the two triangles for fragment.Through here Http://js.do/hightopo/glsl-clock play the final implementation of the results and implementation of code, the implementation of GLSL is the most important is to determine the current coordinate position of the gl_fragcolor color, we will always be divided into the dial, outer ring, scale, The hours, minutes and seconds of the second part of the cod
This chapter implements the weapon design: each time the hand gun, the machine gun can be fired continuously. The weapon spins in either direction to launch bullets.Download source codeFirst add the Weapon class:Weapon base class arm:p ublic cocos2d::sprite{public: //init bullet virtual bool Initbullet () = 0; Launch virtual void fire () = 0; Stop launch for automatic machine gun virtual void stopfire () = 0; Get the bullet ignition position
, actually very simple, the code is as follows: Create Drawnode Auto draw = Drawnode::create (); Add the Drawnode to the layer addChild (draw, 10);Now that we've got the Drawnode object, let's take a look at how to use Drawnode to draw a point with the following code: Draw a point //parameter 1, the position of the point, Parameter 2, the size of the point, Parameter 3, the color of the point, the color value 0-1 of the range of float draw->drawpoint (
, there are only two triangles to draw, the drawing logic of the real dial is fully implemented when the GPU performs Fragment Shading on two triangles.
Through the http://js.do/hightopo/glsl-clock here play the final implementation effect and implementation code, the most important thing to use GLSL is to determine the current Coordinate Position of the gl_FragColor color, we will always be divided into the dial, outer ring, scale, hour hand, minute hand and second hand parts. The continuous B
Using system;
Using system. Collections. Generic;
Public class Utest{Static void main (){Vec2 [] points = new vec2 [1, 20000];Random random = new random (123456 );For (INT I = 0; I {Points [I] = new vec2 (random. Next (200000)/100366f, random. Next (200000)/100366f );
}Int starttick, endtick;
Starttick = system. environment. tickcount;Float divideconquer = (floa
-relatedAccelamplitude, Acceldeccelamplitude,deccelamplitudeOther related actionsActiontween,targetedactionCode sectionAPI for the Jumpby,jumpto classStatic Jumpby * Create (float duration,//duration, in seconds.Const VEC2 position,//jumping distance.Float height,//The height of the jump.int jumps)//number of hops.Static Jumpto * Create (float duration,//duration, in seconds.Const VEC2 position,//The locati
1.drawaDot draw a dot, official explanation
void
Drawdot (const VEC2 pos, float radius, const color4f color)
The point at which the predetermined position is drawn, given the radius and color
Instance:[CPP]View Plaincopy
Auto r= cocos2d::D rawnode::create ();
AddChild (R);
R->drawdot (VEC2 (100,100), 10,color4f::green);
Effect:A gree
= director::getinstance ()->getvisiblesize (); 2 Vec2 origin = Director::getinstance ()- >getvisibleorigin ();So if you want to get the location of the viewable area of the screen and the relative width, you can set it on the basis of these two properties.Instance code:1 //1, Drawnode object is the base object in Cocos2d, can be used to draw some graphics 2 auto rect = Drawnode::create (); 3 //rect->drawrect ( Const COCOS2D::
are defined in planar or in three-dimensional space with three quadratic Bezier curves. The curve starts at p 0 toward P 1 and comes from P 2 to p3. Generally do not go through P1 or P2; These two points are just there to provide direction information. The spacing between p0 and p1 determines how long the curve moves toward the p2 direction before turning to p3.P0 starting point, P3 is the end point, P1,p2 is the control point1.2 Game AppsWe may need to simulate the trajectory of a missile or
. If the number of values in the argument list exceeds the number of elements in the matrix or vector, an error will be raised.If a matrix is used to construct the matrix, then the element values in the parameter matrix are placed in the corresponding position of the new matrix.If the base type (int, float, BOOL) is passed as a parameter to the constructor, but the type of element to construct differs from the data type passed in, the type conversion is used.VEC3 (float)//Initializes each compon
of the image. The Vertex coloring tool sets the vertex position and sends parameters such as the position and texture coordinates to the fragment coloring tool.
The GPU then uses the fragment shader to calculate the final color of each pixel of an object or image. Images are actually just a collection of data. The image document contains the color components and transparency values of each pixel. Because the formula for each pixel is the same, the GPU can streamline the job process for more eff
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.